home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Getting Started / Drawing a Line / GDITEST8.dpr
Encoding:
Text File  |  2003-10-15  |  2.2 KB  |  88 lines

  1. program GDITEST8;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   pen: TGPPen;
  14. begin
  15.   graphics := TGPGraphics.Create(DC);
  16.   pen:= TGPPen.Create(MakeColor(255, 0, 0, 255));
  17.   graphics.DrawLine(pen, 0, 0, 200, 100);
  18.   graphics.Free;
  19.   pen.Free;
  20. end;
  21.  
  22.  
  23. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  24. var
  25.   Handle: HDC;
  26.   ps: PAINTSTRUCT;
  27. begin
  28.   case message of
  29.     WM_PAINT:
  30.       begin
  31.         Handle := BeginPaint(Wnd, ps);
  32.         OnPaint(Handle);
  33.         EndPaint(Wnd, ps);
  34.         result := 0;
  35.       end;
  36.  
  37.     WM_DESTROY:
  38.       begin
  39.         PostQuitMessage(0);
  40.         result := 0;
  41.       end;
  42.  
  43.    else
  44.       result := DefWindowProc(Wnd, message, wParam, lParam);
  45.    end;
  46. end;
  47.  
  48. var
  49.   hWnd     : THandle;
  50.   Msg      : TMsg;
  51.   wndClass : TWndClass;
  52. begin
  53.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  54.    wndClass.lpfnWndProc    := @WndProc;
  55.    wndClass.cbClsExtra     := 0;
  56.    wndClass.cbWndExtra     := 0;
  57.    wndClass.hInstance      := hInstance;
  58.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  59.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  60.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  61.    wndClass.lpszMenuName   := nil;
  62.    wndClass.lpszClassName  := 'GettingStarted';
  63.  
  64.    RegisterClass(wndClass);
  65.  
  66.    hWnd := CreateWindow(
  67.       'GettingStarted',       // window class name
  68.       'Drawing a Line',       // window caption
  69.       WS_OVERLAPPEDWINDOW,    // window style
  70.       Integer(CW_USEDEFAULT), // initial x position
  71.       Integer(CW_USEDEFAULT), // initial y position
  72.       Integer(CW_USEDEFAULT), // initial x size
  73.       Integer(CW_USEDEFAULT), // initial y size
  74.       0,                      // parent window handle
  75.       0,                      // window menu handle
  76.       hInstance,              // program instance handle
  77.       nil);                   // creation parameters
  78.  
  79.    ShowWindow(hWnd, SW_SHOW);
  80.    UpdateWindow(hWnd);
  81.  
  82.    while(GetMessage(msg, 0, 0, 0)) do
  83.    begin
  84.       TranslateMessage(msg);
  85.       DispatchMessage(msg);
  86.    end;
  87. end.
  88.